package com.zmj.framework.util;

import java.util.ArrayList;

public class SimpleSqlStatement {
	ArrayList list = new ArrayList();
	String main = "";

	public SimpleSqlStatement(String mainStatement) {
		this.main = mainStatement;
	}

	public void addCondition(String leftExpression, String condition, String value, String valueClass) {
		if ((value == null) || (value.equals("")))
			return;
		if (valueClass == null) {
			this.list.add(leftExpression + " " + condition + " " + value);
		} else if (valueClass.equals("java.lang.String"))
			this.list.add(leftExpression + " " + condition + "'" + value + "'");
	}

	public String getSqlStatement() {
		StringBuffer buffer = new StringBuffer();

		buffer.append(this.main);

		if (this.list.size() > 0) {
			buffer.append(" where ");
		}
		for (int i = 0; i < this.list.size(); ++i) {
			if (i > 0)
				buffer.append(" and " + this.list.get(i));
			else {
				buffer.append(this.list.get(i));
			}
		}
		return buffer.toString();
	}
}